Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove use of deprecated np.float #20

Merged
merged 5 commits into from
Jan 18, 2022
Merged

remove use of deprecated np.float #20

merged 5 commits into from
Jan 18, 2022

Conversation

javierggt
Copy link
Contributor

@javierggt javierggt commented Dec 16, 2021

Description

This PR makes tiny changes to remove uses of a few deprecated dtypes (sot/skare3#753). This module has no tests, but the change is simple enough.

It also replaces mpl.epoch2num by mpl.date2num. mpl.epoch2num is deprecated in 3.3.0 and un-deprecated in 3.3.1.

Testing

  • [n/a] Passes unit tests (not available)
  • Functional testing:
import sys
sys.path.insert(0, '/Users/javierg/SAO/git/Ska.Matplotlib')

from Ska.Matplotlib import plot_cxctime
from cxotime import CxoTime

x = CxoTime(['2000:200:10:00:54.000', '2000:255:22:05:13.000',
        '2000:260:11:48:03.000', '2000:259:14:18:04.000',
        '2000:261:20:02:12.000', '2000:263:14:31:14.000',
        '2000:116:04:16:24.000', '2000:170:13:42:58.000',
        '2000:282:09:05:04.000', '2000:104:09:57:52.000'])
y = np.array([-0.14152936, -0.08862624,  0.1887119 , -0.04996345, -0.08275661,
         0.00739793, -1.54209896, -0.01827701,  0.02285568, -0.12560554])
plot_cxctime(x, y, '.', label='dy')

@@ -186,7 +186,7 @@ def cxctime2plotdate(times):
# Find the plotdate of first time and use a relative offset from there
times = times.ravel()
t0 = CxoTime(times[0]).unix
plotdate0 = epoch2num(t0)
plotdate0 = date2num(t0) * 1e6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really threw me for a loop. The MPL documentation is pretty bad since it implies that the argument t0 must be a np.datetime type and makes no mention of what happens if you pass in a float. I ended up needing to read the source code to figure out what's happening.

So one thing is that the * 1e6 needs to go inside the date2num() call, and adding a comment # Float arg to date2num is in microsecs would have saved me 10 minutes of digging around.

This change should also be highlighted in the PR description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is kind of a pain. Also, this function was deprecated only for a minor version, then they un-deprecated it :/

Anyway I figured it was ok to replace it. I will add comments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been re-deprecated since 3.5 from what I see in the latest stable docs. Strange.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked this and it was not working. I could swear I tested it, but it must have been with some intermediate version in which the date2num function was different.

In any case, the following line works both in our current version and on 3.5.0:

plotdate0 = date2num(CxoTime(times[0]).datetime)

I might check a couple intermediate versions to see.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still do not know what causes it, but now by chance I got to a configuration where the following statements are equivalent:

t = CxoTime()

epoch2num(t.unix)
date2num(t.datetime)
date2num(t.unix * 1e6)

I got this configuration without noticing and now I can retrace my steps (I basically tried three versions, it failed in all, then I decided to undo everything and then it worked, where it was failing before, so obviously something changed)

The bottomline is that we should take the second option, which worked in a fresh environment, and I suggest you double check.

@taldcroft
Copy link
Member

The change to cxctime2plotdate definitely needs some sort of functional or new unit testing since this is very widely used in Ska tools (mostly via plot_cxctime).

@javierggt javierggt merged commit f2fc351 into master Jan 18, 2022
@javierggt javierggt deleted the deprecated-np-dtypes branch January 18, 2022 19:35
@javierggt javierggt mentioned this pull request Feb 8, 2022
3 tasks
@javierggt javierggt mentioned this pull request Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants